package org.jeecg.modules.wlhy.hycarrier.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.wlhy.hycarrier.entity.HyCarrierReport;
import org.jeecg.modules.wlhy.hycarrier.mapper.HyCarrierReportMapper;
import org.jeecg.modules.wlhy.hycarrier.service.IHyCarrierReportService;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriverReport;
import org.springframework.stereotype.Service;


@Service
public class HyCarrierReportServiceImpl extends ServiceImpl<HyCarrierReportMapper, HyCarrierReport> implements IHyCarrierReportService {

    @Override
    public boolean checkUploadStatus(String carrierId, int reportPlatformType){

        LambdaQueryWrapper<HyCarrierReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HyCarrierReport::getCarrierId, carrierId);
        queryWrapper.eq(HyCarrierReport::getReportPlatformType, reportPlatformType);
        HyCarrierReport hyCarrierReport = this.getOne(queryWrapper);
        if (hyCarrierReport != null ) {
            if ("1".equals(hyCarrierReport.getCarrierUploadStatus())) {
                return true;
            }
        }

        return false;
    }

    @Override
    public boolean saveCarrierReport(HyCarrierReport hyCarrierReport){

        HyCarrierReport report = this.getOne(new LambdaQueryWrapper<HyCarrierReport>()
                .eq(HyCarrierReport::getCarrierId, hyCarrierReport.getCarrierId())
                .eq(HyCarrierReport::getReportPlatformType, hyCarrierReport.getReportPlatformType())
                .eq(HyCarrierReport::getCompanyId, hyCarrierReport.getCompanyId()));

        if (null != report) {
            hyCarrierReport.setId(report.getId());
            return this.updateById(hyCarrierReport);
        }

        return this.save(hyCarrierReport);
    }

    @Override
    public HyCarrierReport getUploadStatus(String carrierId, String companyId, int reportPlatformType) {
        LambdaQueryWrapper<HyCarrierReport> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HyCarrierReport::getCarrierId, carrierId);
        queryWrapper.eq(HyCarrierReport::getReportPlatformType, reportPlatformType);
        queryWrapper.eq(HyCarrierReport::getCompanyId, companyId);
        return this.getOne(queryWrapper);
    }
}
